package com.imcode.exceptiondemo;

public class CustomExceptionDemo {

    public static void main(String[] args) {
        /*
        try {
            login("admin", "1234567");
        } catch (UsernameNotFindException e1) {
            e1.printStackTrace();
        } catch (PasswordErrorException e2) {
            e2.printStackTrace();
        }*/

        try {
            login("admin", "123456");
        }catch (UsernameNotFindException | PasswordErrorException e){
            e.printStackTrace();
        }


    }


    /**
     * @param username admin
     * @param password 123456
     */
    public static void login(String username, String password)
            throws UsernameNotFindException, PasswordErrorException {
        if (!"admin".equals(username)) {
            throw new UsernameNotFindException("用户名不存在");
        }

        if (!"123456".equals(password)) {
            throw new PasswordErrorException("密码错误");
        }

        System.out.println("登陆成功");
    }
}
